package com.sl.crawler.robot;

import com.sl.crawler.common.utils.file.FilePathUtils;
import com.sl.crawler.robot.output.IOutput;
import com.sl.crawler.robot.utils.ConfigUtils;

import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by shiling on 2017/6/16.
 */
@XmlRootElement
public class CrawlerConfig {

    /**
     * 输出csv路径
     */
    private String outputCsvPath;

    /**
     * 解析结果配置文件路径
     */
    private String parseConfigPath;

    /**
     * 起始抓取url地址
     */
    private List<String> startCrawlerUrl;

    /**
     * 解析结果配置
     */
    private List<List<String>> parseConfig;

    /**
     * 输出渠道
     */
    private List<IOutput> outputList = new ArrayList<>();

    /**
     * 下一个地址的选择cssPath或者xpath
     */
    private String nextUrlSelectPath;

    public String getOutputCsvPath() {
        return outputCsvPath;
    }

    public void setOutputCsvPath(String outputCsvPath) {
        this.outputCsvPath = outputCsvPath;
    }

    public String getParseConfigPath() {
        return parseConfigPath;
    }

    public void setParseConfigPath(String parseConfigPath) {
        this.parseConfigPath = FilePathUtils.getAbsolutePath(parseConfigPath);
        initParseConfig();
    }

    private void initParseConfig() {
        List<List<String>> xpathConfigSelenium = ConfigUtils.getConfigList(this.parseConfigPath);
        this.setParseConfig(xpathConfigSelenium);
    }

    public List<String> getStartCrawlerUrl() {
        return startCrawlerUrl;
    }

    public void setStartCrawlerUrl(List<String> startCrawlerUrl) {
        this.startCrawlerUrl = startCrawlerUrl;
    }

    public List<List<String>> getParseConfig() {
        return parseConfig;
    }

    public void setParseConfig(List<List<String>> parseConfig) {
        this.parseConfig = parseConfig;
    }

    public String getNextUrlSelectPath() {
        return nextUrlSelectPath;
    }

    public void setNextUrlSelectPath(String nextUrlSelectPath) {
        this.nextUrlSelectPath = nextUrlSelectPath;
    }

    public List<IOutput> getOutputList() {
        return outputList;
    }

    public void setOutputList(List<IOutput> outputList) {
        this.outputList = outputList;
    }

    public void addOutput(IOutput output) {
        this.outputList.add(output);
    }
}
